﻿using System;
using System.Net;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace HobSoft.SoccerBet2014.Domain.Models.Site
{
    using Core;
    [Serializable]
    [DataContract]
    public class PersistentCookie : IModel
    {
        public PersistentCookie()
        {
            Expires = DateTime.MinValue;
            TimeStamp = DateTime.Now;
        }

        public PersistentCookie(Cookie cookie)
        {
            Name = cookie.Name;
            Value = cookie.Value;
            Path = cookie.Path;
            Domain = cookie.Domain;
            Comment = cookie.Comment;
            Discard = cookie.Discard;
            Expired = cookie.Expired;
            Expires = cookie.Expires;
            HttpOnly = cookie.HttpOnly;
            Port = cookie.Port;
            Secure = cookie.Secure;
            TimeStamp = cookie.TimeStamp;
            Version = cookie.Version;
        }

        public Cookie ToCookie()
        {
            Cookie cookie = new Cookie(Name, Value, Path, Domain);
            if (!string.IsNullOrEmpty(Port))
                cookie.Port = Port;
            if (!string.IsNullOrEmpty(Comment))
                cookie.Comment = Comment;
            cookie.Discard = Discard;
            cookie.HttpOnly = HttpOnly;
            cookie.Expires = Expires;
            cookie.Secure = Secure;
            cookie.Version = Version;
            return cookie;
        }
        [DataMember]
        public string Comment { get; set; }
        [DataMember]
        public Uri CommentUri { get; set; }
        [DataMember]
        public bool Discard { get; set; }
        [DataMember]
        public string Domain { get; set; }
        [DataMember]
        public bool Expired { get; set; }
        [DataMember]
        public DateTime Expires { get; set; }
        [DataMember]
        public bool HttpOnly { get; set; }

        [Required]
        [MinLength(1)]
        [MaxLength(200)]
        [DataMember(IsRequired = true)]
        public string Name { get; set; }
        [DataMember]
        public string Path { get; set; }
        [DataMember]
        public string Port { get; set; }
        [DataMember]
        public bool Secure { get; set; }
        [DataMember]
        public DateTime TimeStamp { get; set; }

        [Required]
        [MaxLength(800)]
        [DataMember(IsRequired = true)]
        public string Value { get; set; }
        [DataMember]
        public int Version { get; set; }
    }

}
